package com.mybatis.config;

import org.web3j.protocol.Web3j;
import org.web3j.protocol.admin.Admin;
import org.web3j.protocol.geth.Geth;
import org.web3j.protocol.http.HttpService;

/**
 * @author liuxiaoding
 * @Date 2019/12/19
 **/
public class EthService {
    /**
     * geth节点可调用的json-rpc接口地址和端口
     */
    private static final String URL = "http://18.191.237.227:8545/";

    /**
     * 初始化web3j普通api调用
     *
     * @return web3j
     */
    public static Web3j initWeb3j() {
        return Web3j.build(getService());
    }

    /**
     * 初始化personal级别的操作对象
     * @return Geth
     */
    public static Geth initGeth(){
        return Geth.build(getService());
    }

    /**
     * 初始化admin级别操作的对象
     * @return Admin
     */
    public static Admin initAdmin(){
        return Admin.build(getService());
    }

    /**
     * 通过http连接到geth节点
     * @return
     */
    private static HttpService getService(){
        return new HttpService(URL);
    }
}
